package com.jrx.anytxn.accounting.controller;

import com.jrx.anytxn.accounting.dto.GlInterfaceExcpReportRes;
import com.jrx.anytxn.accounting.service.IGlInterfaceExcpReportService;
import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jrx.auth.filter.service.InfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName GlInterfaceExcpReportController
 * @Description: 总账流水例外报表管理
 * @Author yf
 * @Date 2019/9/23 0023
 * @Version V1.0
 **/
@Api(tags = "总账流水例外报表管理")
@RestController
@RequestMapping("account/glInterfaceExcpReportController")
public class GlInterfaceExcpReportController {

    private static final Logger logger = LoggerFactory.getLogger(GlInterfaceExcpReportController.class);

    @Autowired
    private IGlInterfaceExcpReportService glInterfaceExcpReportService;

    @Resource
    private InfoService infoService;

    @ApiOperation("分页查询总账流水例外报表信息")
    @GetMapping("/pageNum/{pageNum}/pageSize/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", required = true)})
    public TxnRespResult<TxnPage<GlInterfaceExcpReportRes>> getAllByPage(@PathVariable(value = "pageNum") Integer pageNum, @PathVariable(value = "pageSize") Integer pageSize, @RequestParam("customerId") String customerId, @RequestParam("loanId") String loanId) {
        TxnRespResult<TxnPage<GlInterfaceExcpReportRes>> result = new TxnRespResult<>();
        try {
            result.getSuccess(glInterfaceExcpReportService.getPage(pageNum, pageSize,String.valueOf(infoService.getUser().getProjectId()),customerId,loanId));
        } catch (TxnException e) {
            logger.error("分页查询总账流水例外报表信息异常：{}", e);
            result.getFail(e.getErrCode(), e.getErrMsg());
        }
        return result;
    }

    @ApiOperation("通过主键查询总账流水例外报表信息")
    @GetMapping("/{id}/{tenantId}/{customerId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true),
            @ApiImplicitParam(name = "tenantId", value = "租户ID", required = true),
            @ApiImplicitParam(name = "customerId", value = "客户ID", required = true)})
    public TxnRespResult<GlInterfaceExcpReportRes> getModalByPrimaryKey(@PathVariable(value = "id") Long id,@PathVariable("tenantId") String tenantId,@PathVariable("customerId") String customerId) {
        TxnRespResult<GlInterfaceExcpReportRes> result = new TxnRespResult<>();
        try {
            result.getSuccess(glInterfaceExcpReportService.getModalByIdAndTenIdAndCusId(id,tenantId,customerId));
        } catch (TxnException e) {
            logger.error("通过主键查询总账流水例外报表信息异常：{}", e);
            result.getFail(e.getErrCode(), e.getErrMsg());
        }
        return result;
    }
}
